package com.hyj.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hyj.service.ModulesService;
import com.hyj.mapper.ModulesMapper;
import com.hyj.mapper.RoleModulesMapper;
import com.hyj.entity.Modules;
import com.hyj.entity.RoleModules;

@Service
public class ModulesServiceImp implements ModulesService {
	@Autowired
	private ModulesMapper modulesmapper;
	@Autowired
	private RoleModulesMapper rolemodulesmapper;
	//根据角色id查出所管理的模块
	@Override
	public List<Modules> selectModules(List<Integer> list) {
		// TODO Auto-generated method stub
		return modulesmapper.selectModules(list);
	}
	//根据父类查子类模块
	@Override
	public List<Modules> selectModulesByParentId(Integer parentId) {
		// TODO Auto-generated method stub
		return modulesmapper.selectModulesByParentId(parentId);
	}
	//查询所有模块
	@Override
	public List<Modules> selectChildrenModules() {
		// TODO Auto-generated method stub
		return modulesmapper.selectChildrenModules();
	}
	//添加子节点
	@Override
	public Integer addModules(Modules modules) {
		// TODO Auto-generated method stub
		Integer addModules=null;
	 List<Modules> selectByName = modulesmapper.selectByName(modules);
	 if(selectByName.size()==0){
		 modulesmapper.addModules(modules);
	 }else{
		 addModules=-1;
	 }
	 return addModules;
	}
	//根据id删除模块子节点
	@Override
	public Integer deleteModules(Integer id) {
		// TODO Auto-generated method stub
		return modulesmapper.deleteModules(id);
	}
	//根据rid查询管理模块
	@Override
	public List<Integer> selectModuleByRid(Integer id) {
		// TODO Auto-generated method stub
		List<RoleModules> selectRoleModulesByRId = rolemodulesmapper
				.selectRoleModulesByRId(id);
		List<Integer> rmlist = new ArrayList<Integer>();
		for (int i = 0; i < selectRoleModulesByRId.size(); i++) {
			rmlist.add(selectRoleModulesByRId.get(i).getModuleId());
		}

		return rmlist;
	}

	//修改模块
		@Override
		public Integer updateModule(Modules modules) {
				return modulesmapper.updateModule(modules);
			}


}
